import java.util.Arrays;

/**
 * @classname:exercise
 * @description:
 * @author: Mr.Z
 * @date: 2020/11/28 18:57
 * @version: 0.1
 * @since:1.8
 */
public class exercise {
    public static void main(String[] args) {
        int[] array = {4,3,5,2,6,4,7,9};
        System.out.println(Arrays.toString(array));
//        bubble(array);
//        select(array);
            insert(array);
        System.out.println(Arrays.toString(array));
    }

    private static void insert(int[] array) {
        for (int i = 0; i < array.length; i++) {
            int lastIndex = i-1;
            int v = array[i];
            while (lastIndex>-1&&v<array[lastIndex]){
                array[lastIndex+1] = array[lastIndex];
                lastIndex--;
            }
            array[lastIndex+1] = v;

        }
    }

    private static void select(int[] array) {
        for(int tian = array.length-1;tian>=0;tian--){
            int max = array[0];
            int maxIndex = 0;
            for (int i = 1; i <= tian; i++) {
                if(array[i]>max){
                    max = array[i];
                    maxIndex = i;
                }
            }
            int temp = array[tian];
            array[tian]= array[maxIndex];
            array[maxIndex] = temp;
        }
    }

    private static void bubble(int[] array) {
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array.length-i-1; j++) {
                if(array[j]>array[j+1]){
                    int temp = array[j+1];
                    array[j+1] = array[j];
                    array[j] = temp;
                }
            }

        }
    }
}
